<template>
  <div id="main" style="width: 100%; height: 278px; float: left"></div>
</template>

<script>
import * as echarts from "echarts";
// import { getselectRoomBedSum } from "@/api/system/emporty";
// require("echarts/theme/macarons"); // echarts theme
// import resize from '@/views/dashboard/mixins/resize'
export default {
  name: "checkin",
  // mixins: [resize],
  data() {
    return {
      myChart2: "",
      roombedSum:[],
      opinionData2: [
        { value: 1048, name: "可入住" },
        { value: 735, name: "已入住" },
        { value: 580, name: "已锁定" },
        // { value: 484, name: "Union Ads" },
        // { value: 300, name: "Video Ads" },
      ],
    };
  },
  created(){
    // this.selectRoomBedList();
  },
  mounted() {
    // window.addEventListener("resize", this.handleResize);
    window.addEventListener("resize", ()=>{
      if(this.myChart2){
        this.myChart2.resize();
      }
    });
  },
  beforeDestroy() {
    if (!this.myChart2) {
      return
    }
    this.myChart2.dispose()
    this.myChart2 = null
  },
  destroyed() {
    window.removeEventListener("resize", () => {
      this.myChart2.resize();
    });
  },
  methods: {
    // handleResize() {
    //   this.myChart2.resize();
    // },
    // selectRoomBedList() {
    //   getselectRoomBedSum().then((res) => {
    //     this.roombedSum = res.data.data;
    //     this.$nextTick(() => {
    //       this.drawLine();
    //     });
    //   });
    // },
    drawLine() {
      this.myChart2 = echarts.init(document.getElementById("main"));
      let arr=[];
      this.roombedSum.forEach((item)=>{
        if(item.name=="男生剩余床位"||item.name=="女生剩余床位"){
          arr.push(item)
        }
      })
      this.myChart2.setOption({
        title: {
          text: "今日业务预约情况占比",
          // subtext: "Fake Data",
          // left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        color: ["#1ad9b6","#fec05a","#ffdb5c", "#5198ee"],
        legend: {
          orient: "vertical",
          left: "left",
          left: "5%",
          textStyle: {
            color: "#333",
            fontSize: 14,
          },
        },
        series: [
          {
            name: "宿舍使用率",
            type: "pie",
            radius: "60%",
            center: ["48%", "65%"],
            data: arr,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
            itemStyle: {
              normal: {
                label: {
                  show: true,
                  //position:'inside',
                  fontSize: 14,
                  formatter: "{b}({d}%)",
                },
              },
              labelLine: { show: true },
            },
          },
        ],
      });
    },
  },
};
</script>
<style scoped>

</style>
